﻿
    <Window x:Class="MContracts.Dialogs.ImportDialogWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Импорт календарного плана" 
        x:Name="ImportDlg" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        HorizontalContentAlignment="Stretch" Height="975" Width="1063" 
        xmlns:vw="clr-namespace:MContracts.ViewModel" xmlns:converters="clr-namespace:MContracts.Classes.Converters" DataContext="{Binding}" WindowStartupLocation="CenterOwner" MinHeight="600" MinWidth="1000" xmlns:my="clr-namespace:MContracts.Controls" Closing="ImportDlg_Closing" Closed="ImportDlg_Closed" Unloaded="ImportDlg_Unloaded" Icon="/MContracts;component/Resources/importmail.png" WindowState="Maximized">
   
        <Window.Resources>
            <vw:ExcelReaderTypeToBoolConverter x:Key="ExcelReaderTypeToBoolConverterApplied" />
            <vw:WordReaderTypeToBoolConverter x:Key="WordReaderTypeToBoolConverterApplied" />
            <vw:NoReaderToBoolConverter x:Key="NoReaderToBoolConverterApplied" />
            <vw:AnyReaderToBoolConverter x:Key="AnyReaderToBoolConverterApplied" />
            <vw:SaveAllSavingSettingToRadioBtnCheckedConverter x:Key="SaveAllSavingSettingToRadioBtnCheckedConverterApplied" />
            <vw:SaveNewSavingSettingToRadioBtnCheckedConverter x:Key="SaveNewSavingSettingToRadioBtnCheckedConverterApplied" />

            <Style TargetType="TextBox">
                <Setter Property="Validation.ErrorTemplate">
                    <Setter.Value >
                        <ControlTemplate>
                            <DockPanel LastChildFill="True">
                                <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="18" FontWeight="Bold" ToolTip="{Binding ElementName=adornedPlaceHolder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">*</TextBlock>
                                <Border BorderBrush="Red" BorderThickness="1">
                                    <AdornedElementPlaceholder x:Name="adornedPlaceHolder"></AdornedElementPlaceholder>
                                </Border>
                            </DockPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <vw:SheetIndexToListIndexConverter x:Key="SheetIndexToListIndexConverterApplied" />
            <converters:DateTimeToShortDateConverter x:Key="DateTimeToShortDateConverter"/>
            <converters:LevelToMarginConverter x:Key="LevelToMarginConverter" LeftMargin="8" OtherMargin="0" />
            <converters:StageConditionConverter x:Key="StageConditionConverter"/>
            <converters:StageConditionToImageConverter x:Key="StageConditionToImageConverter"/>
    </Window.Resources>

        <Grid Margin="0,0,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="270" />
            <ColumnDefinition Width="160" />
            <ColumnDefinition Width="74" />
            <ColumnDefinition Width="*" />
    
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="100" />
            <RowDefinition Height="300*" />
        </Grid.RowDefinitions>
        <Button  HorizontalAlignment="Stretch" Name="btnClose" Width="160" Command="{Binding Path=CloseCommand}" Grid.Column="1">
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                <Image Source="/MContracts;component/Resources/window-close.png"  Width="16" Height="16" HorizontalAlignment="Left" />
                <TextBlock Margin="5,0,0,0" Text="Закрыть без передачи"  HorizontalAlignment="Right" />
            </StackPanel>

        </Button>
        
       
        <GroupBox Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="1" Header="Укажите путь к файлу-источнику" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="groupBox1" VerticalAlignment="Stretch">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="3" />
                    <RowDefinition Height="26*" />
                    <RowDefinition Height="45" />
                </Grid.RowDefinitions>
                <TextBox Grid.Column="0" Grid.Row="1" HorizontalAlignment="Stretch" Name="txtFileName" VerticalAlignment="Stretch" DataContext="{Binding}" Text="{Binding Path=Importer.Filename}" Margin="2,0,5,0" />
                <Button  Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,6,0" Name="button1" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Command="{Binding Path=OpenFileCommand}">
                    <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                        <Image Source="/MContracts;component/Resources/fileopen.png"  Width="16" Height="16" HorizontalAlignment="Left" />
                        <TextBlock Margin="5,0,0,0" Text="Открыть файл"  HorizontalAlignment="Right" />
                    </StackPanel>
                </Button>
                <ProgressBar Grid.Row="2" Grid.ColumnSpan="2" Height="30" HorizontalAlignment="Stretch" Name="prg" VerticalAlignment="Bottom" />
            </Grid>
        </GroupBox>
        <TabControl Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="2" HorizontalAlignment="Stretch" Name="tbView" VerticalAlignment="Stretch">
            <TabItem Header="Исходные данные">
                <Grid Name="SourceDataGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="150" />
                        <RowDefinition Height="200" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="152*" />
                        <ColumnDefinition Width="184*" />
                        <ColumnDefinition Width="721*" />
                    </Grid.ColumnDefinitions>
                    <GroupBox Height="45" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="47" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="152" />
                                <ColumnDefinition Width="152" />
                                <ColumnDefinition Width="152*" />
                                <ColumnDefinition Width="152" />
                                <ColumnDefinition Width="152" />
                                <ColumnDefinition Width="152" />
                           
                            </Grid.ColumnDefinitions>
                            <Button  Grid.Column="0" Grid.Row="1" Height="30" HorizontalAlignment="Stretch" Margin="0,5,0,0" Name="btnWDReload" VerticalAlignment="Top" Width="148"   Command="{Binding Path=ReopenFileCommand}">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/document-import.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Загрузить КП"  HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button>
                            <Button Grid.Column="1" Grid.Row="1" Height="30" HorizontalAlignment="Left" Margin="0,5,0,0" Name="btnWDReapplyScheme" VerticalAlignment="Top" Width="148"   Command="{Binding Path=ReapplySchemeCommand}" Click="btnWDReapplyScheme_Click">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/document-save-as.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Сохранить"  HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button>

                            <Button  Grid.Column="2" Height="30" HorizontalAlignment="Left" Margin="0,5,0,0" Name="btnWDReReload" VerticalAlignment="Top" Width="148"   Command="{Binding Path=ReopenFileCommand}">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/undo.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Отменить изменения"  HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button>

                            <Button  Grid.Column="5" Height="30" HorizontalAlignment="Left" Margin="0,5,0,0" Name="btnSaveScheme" VerticalAlignment="Top" Width="148"  Command="{Binding Path=SaveSchemeCommand}" >
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/table_save.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Сохранить схему"  HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button>
                        </Grid>
                    </GroupBox>

                    <ComboBox Name="cmbxImportingScheme" Margin="0,15,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Visibility="Collapsed" ItemsSource="{Binding Importer.Schemes}" SelectedItem="{Binding Importer.Scheme}"/>
                    <my:CellsGridControl x:Name="CellsGridPreview" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="3" BorderThickness="1" BorderBrush="LightGray"/>
                    <GroupBox Grid.ColumnSpan="3"  Grid.Row="2" Grid.RowSpan="2" Header="Импорт" HorizontalAlignment="Stretch" Name="gbxPreSettings" VerticalAlignment="Stretch" Visibility="{Binding Converter={StaticResource NoReaderToBoolConverterApplied}, Path=Importer.ActiveReader}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Name="lblImportInfo" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap">
                                Для того, чтобы начать импорт нажмите на кнопку "Загрузить данные" и укажите файл, из которого предстоит 
                                импортировать данные об этапах календарного плана. Прочитанные строки преобразуются в набор этапов, сразу 
                                же после чтения файла. Полученный из файла набор этапов можно увидеть на вкладке "Результаты импорта". 
                                Если требуется откорректировать настройки чтения - Вы можете сделать это уже после загрузки файла, введя 
                                необходимые настройки и нажав кнопку "Перечитать источник". После этого чтение данных и импорт будут осуществлены 
                                повторно и на вкладке "Результаты импорта" будет представлен набор этапов, полученный в соответствии с новыми 
                                настройками. Нажатие кнопки "Повторить импорт" приводит к повторному импорту данных без нового обращения 
                                к файлу-источнику.
                            </TextBlock>
                        </Grid>
                    </GroupBox>


                    <GroupBox Header="Настройки Microsoft Excel" Grid.Column="0" Grid.ColumnSpan="4"  Grid.Row="2"  HorizontalAlignment="Stretch" Name="gbxExcelSettings" VerticalAlignment="Stretch" Visibility="{Binding Converter={StaticResource ExcelReaderTypeToBoolConverterApplied}, Path=Importer.ActiveReader}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="200*" />
                                                <ColumnDefinition Width="60*" />
                                                <ColumnDefinition Width="200*" />
                                                <ColumnDefinition Width="60*" />
                                                <ColumnDefinition Width="20*" />
                                                <ColumnDefinition Width="546*" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <Label Content="Лист в файле MS Excel" Height="35" HorizontalAlignment="Stretch" Name="lblExcelSheet" VerticalAlignment="Bottom" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Bottom" />
                                            <ComboBox Height="22" HorizontalAlignment="Stretch" Name="cbExcelSheet" VerticalAlignment="Bottom" Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="0" ItemsSource="{Binding Path=Importer.FileElements}" SelectedIndex="{Binding Path=Importer.ActiveFileElementIndex, Converter={StaticResource SheetIndexToListIndexConverterApplied}}" />
                                            <Label Content="Нач. строка области данных" Grid.Row="1" Height="40" HorizontalAlignment="Left" Name="lblXLTopRow" VerticalAlignment="Bottom" Width="166" Grid.ColumnSpan="2" VerticalContentAlignment="Bottom" />
                                            <Label Content="Нач. столбец области данных" Height="37" Name="lblXLLeftCol" VerticalAlignment="Bottom" Grid.Row="2" VerticalContentAlignment="Bottom" />
                            <TextBox Text="{Binding Path=Importer.StartRow, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Right" Grid.Column="1" Grid.Row="1" Height="20" HorizontalAlignment="Stretch" Name="txtXLTopRow" VerticalAlignment="Bottom" Margin="0,0,5,0"/>
                            <TextBox Text="{Binding Path=Importer.StartColumn, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Right" Grid.Row="2" Height="20" HorizontalAlignment="Stretch" Name="txtXLLeftCol" VerticalAlignment="Bottom" Grid.Column="1" Margin="0,0,5,0"/>
                                            <Label Content="Кон. строка области данных"   Margin="0, 0, 0, 0" Grid.Column="2" Grid.Row="1" Height="40" Name="lblXLBottomRow" HorizontalAlignment="Left" VerticalAlignment="Bottom" VerticalContentAlignment="Bottom" />
                            <TextBox Text="{Binding Path=Importer.FinishRow, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}"  HorizontalContentAlignment="Right" Grid.Column="3" Grid.Row="1" Height="20" HorizontalAlignment="Stretch"  Name="txtXLBottomRow" VerticalAlignment="Bottom"  Margin="0,0,5,0"/>
                                            <Label Content="Кон. столбец области данных" Margin="0, 0, 0, 0" Grid.Column="2" Grid.Row="2" Height="37" HorizontalAlignment="Left" Name="lblXLRightCol" VerticalAlignment="Bottom" VerticalContentAlignment="Bottom" />
                            <TextBox Text="{Binding Path=Importer.FinishColumn, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Right"  Grid.Column="3" Grid.Row="2" Height="20" HorizontalAlignment="Stretch"  Name="txtXLRightCol" VerticalAlignment="Bottom" Margin="0,0,5,0"/>
                            <Button  Grid.Column="5" Height="23" HorizontalAlignment="Left" Name="btnXLView" VerticalAlignment="Bottom" Width="148"  Command="{Binding Path=ShowAppCommand}">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/page_excel.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Просмотр в MS Excel"   HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button >
                        </Grid>
                                    </GroupBox>
                    <GroupBox Header="Настройки Micrisoft Word" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4"  HorizontalAlignment="Stretch" Name="gbxWordSettings" VerticalAlignment="Stretch" Visibility="{Binding Converter={StaticResource WordReaderTypeToBoolConverterApplied}, Path=Importer.ActiveReader}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="180*" />
                                                <ColumnDefinition Width="60*" />
                                                <ColumnDefinition Width="180*" />
                                                <ColumnDefinition Width="60*" />
                                                <ColumnDefinition Width="20*" />
                                                <ColumnDefinition Width="546*" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="40" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <Label Content="Таблица MS Word" Height="35" HorizontalAlignment="Stretch" Name="lblWDTable" VerticalAlignment="Bottom" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Bottom" Margin="0,0,14,0" />
                                            <ComboBox Height="22" HorizontalAlignment="Stretch" Margin="0,19,0,0" Name="cbWDTable" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.Column="1" Grid.RowSpan="2"  ItemsSource="{Binding Path=Importer.FileElements}" SelectedIndex="{Binding Path=Importer.ActiveFileElementIndex, Converter={StaticResource SheetIndexToListIndexConverterApplied}}"/>
                                            <Label Content="Нач. строка области данных" Grid.Row="1" Height="40" HorizontalAlignment="Left" Name="lblWDTopRow" VerticalAlignment="Bottom"  Grid.ColumnSpan="2" VerticalContentAlignment="Bottom" />
                                            <Label Content="Кон. строка области данных" Margin="0, 0, 0, 0" Height="40" HorizontalAlignment="Left"  Name="lblWDBottomRow" VerticalAlignment="Bottom" Grid.Row="1" VerticalContentAlignment="Bottom" Grid.Column="2"/>
                                            <TextBox Text="{Binding Path=Importer.StartRow, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}"  HorizontalContentAlignment="Right" Grid.Column="1" Grid.Row="1" Height="20" HorizontalAlignment="Stretch" Name="txtWDTopRow" VerticalAlignment="Bottom" Margin="0,0,5,0"/>
                                            <TextBox Text="{Binding Path=Importer.FinishRow, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Right"  Grid.Row="1" Height="20" HorizontalAlignment="Stretch" Name="txtWDBottomRow" VerticalAlignment="Bottom" Grid.Column="3" Margin="0,0,5,0" />
                            <Button Grid.Column="5" Height="23" HorizontalAlignment="Left" Margin="0,16,0,0" Name="btnWDView" VerticalAlignment="Top" Width="148" Command="{Binding Path=ShowAppCommand}">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                                    <Image Source="/MContracts;component/Resources/page_word.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                                    <TextBlock Margin="5,0,0,0" Text="Просмотр в MS Word"   HorizontalAlignment="Right" />
                                </StackPanel>
                            </Button>
                               </Grid>
                                    </GroupBox>
                    <GroupBox Grid.Row="3" Grid.ColumnSpan="3" Header="Настройки импорта" HorizontalAlignment="Stretch" Name="gbxItemSettings" VerticalAlignment="Stretch" >
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" DataContext="{Binding}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="170*" />
                                <ColumnDefinition Width="200*" />
                                <ColumnDefinition Width="300*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                                <RowDefinition Height="30*" />
                            </Grid.RowDefinitions>
                            <RadioButton Content="удалить незакрытые этапы исходного КП"  HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="0" Margin="10,0,0,0" Name="rbSaveAll" VerticalAlignment="Stretch" GroupName="IfNumbersAreEqual"  Checked="rbSaveAll_Checked" />
                            <Label Content="Режим импорта"  HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Margin="6,0,0,0" Name="label1" VerticalAlignment="Stretch" />
                            <RadioButton Content="сохранить этапы исходного КП" Height="16" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" Name="rbSaveNew" VerticalAlignment="Stretch"  GroupName="IfNumbersAreEqual" Checked="rbSaveNew_Checked" IsChecked="True" />
                            <Label Content="Алгоритм НДС по умолчанию"  HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Margin="0,0,0,0" Name="label2" VerticalAlignment="Stretch" />
                            <ComboBox Height="22" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="cbNDS" Grid.Row="1" VerticalAlignment="Top"  Grid.Column="1"   ItemsSource="{Binding Path=Repository.Ndsalgorithms}" SelectedItem="{Binding Path=Importer.DefaultNdsalgorithm, Mode=TwoWay}"/>

                            <Label Content="Ставка НДС по умолчанию"  HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="2" Margin="0,0,0,0" Name="label3" VerticalAlignment="Stretch" />
                            <ComboBox Height="22" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="cbNDSValue" Grid.Row="3" VerticalAlignment="Top"  Grid.Column="1"   ItemsSource="{Binding Path=Repository.Nds}" SelectedItem="{Binding Path=Importer.DefaultNds, Mode=TwoWay}"/>


                            <Label Content="Сопоставлять этапы генерального договора и ДС"  HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="4" Margin="0,0,6,0" Name="labelLink" VerticalAlignment="Stretch" />
                            <RadioButton Content="по номеру этапа" Height="16" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="1" Margin="10,0,0,0" Name="rbStageNum" VerticalAlignment="Stretch"  GroupName="StageBinding"  IsChecked="True" Checked="rbStageNum_Checked" />
                            <RadioButton Content="по названию этапа" Height="16" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1" Margin="10,0,10,0" Name="rbStageName" VerticalAlignment="Stretch"  GroupName="StageBinding"  IsChecked="false" Checked="rbStageName_Checked" />

                            <RadioButton Content="по коду стройки"  HorizontalAlignment="Left" Grid.Row="6" Grid.Column="1" Margin="10,0,0,0" Name="rbObjectCode" VerticalAlignment="Stretch" GroupName="StageBinding" Checked="rbObjectCode_Checked" />
                            

                            <CheckBox Content="использовать указанную дату начала этапа по умолчанию"  HorizontalAlignment="Stretch" Grid.Column="2" Grid.Row="2" Margin="10,5,0,0" Name="chbxUseDefaultStartDate"  IsChecked="{Binding Path=Importer.UseDefaultStartDate}" VerticalAlignment="Stretch" Checked="chbxUseDefaultStartDate_Checked" ToolTip="В случае установки флага указанная ниже дата будет использована в качестве даты начала для всех этапов"/>
                            <DatePicker Height="22" Width="120" SelectedDate="{Binding Path=Importer.DefaultStartDate}" HorizontalAlignment="Left" Margin="10,0,0,0" Name="dtmDefaultStartDate" Grid.Row="3" VerticalAlignment="Top"  Grid.Column="2" />

                            <CheckBox Content="использовать указанную дату окончания этапа по умолчанию"  HorizontalAlignment="Stretch" Grid.Column="2" IsChecked="{Binding Path=Importer.UseDefaultFinDate}" Grid.Row="4" Margin="10,5,0,0" Name="chbxUseDefaultFinDate" VerticalAlignment="Stretch" Checked="chbxUseDefaultFinDate_Checked" ToolTip="В случае установки флага указанная ниже дата будет использована в качестве даты окончания для всех этапов" />
                            <DatePicker Height="22" Width="120" SelectedDate="{Binding Path=Importer.DefaultFinDate}" HorizontalAlignment="Left" Margin="10,0,0,0" Name="dtmDefaultFinDate" Grid.Row="5" VerticalAlignment="Top"  Grid.Column="2" />


                            <Label Content="Подтип НТП по умолчанию"  HorizontalAlignment="Stretch" Grid.Column="3" Grid.Row="0"  Margin="10,0,0,0" Name="label4" VerticalAlignment="Stretch" />
                            <ComboBox Height="22" HorizontalAlignment="Stretch" Margin="10,0,0,0" Name="cbNTPSubview" Grid.Row="1" VerticalAlignment="Top"  Grid.Column="2"   ItemsSource="{Binding Path=Repository.Ntpsubviews}" SelectedItem="{Binding Path=Importer.DefaultNTPSubview, Mode=TwoWay}"/>



                        </Grid>
                    </GroupBox>

                </Grid>               
            </TabItem>
            <TabItem Header="Просмотр результата импорта" Name="tshResults">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                    <DataGrid Grid.Row="0" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Single" SelectedItem="{Binding SelectedStage}" SelectionUnit="FullRow"
                                          HorizontalScrollBarVisibility="Disabled" Margin="3" ItemsSource="{Binding Path=Stages}"
                                          HeadersVisibility="Column" AutoGenerateColumns="False" x:Name="StageDataGrid"
                                          HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <DataGrid.Columns>

                            <DataGridTemplateColumn Header="№" Width="Auto" IsReadOnly="True" CanUserSort="False" CanUserReorder="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Num}" Margin="{Binding Path=Level, Converter={StaticResource LevelToMarginConverter}}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>


                            <DataGridTemplateColumn Header="Содержание этапа" Width="6*" IsReadOnly="True" CanUserSort="False" CanUserReorder="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock  Text="{Binding Subject}" TextWrapping="Wrap"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTemplateColumn Header="Начало" Width="2*" IsReadOnly="True" CanUserSort="False" CanUserReorder="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Startsat, Converter={StaticResource DateTimeToShortDateConverter}}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTemplateColumn Header="Окончание" Width="2*" CanUserSort="False" CanUserReorder="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Endsat, Converter={StaticResource DateTimeToShortDateConverter}}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTextColumn Binding="{Binding Price}" Header="Сумма" Width="*" CanUserSort="False" CanUserReorder="False" x:Name="PriceColumn"/>
                            <DataGridTextColumn Binding="{Binding Code}" Header="Объект" Width="*" CanUserSort="False" CanUserReorder="False" x:Name="CodeColumn"/>

                            <DataGridTemplateColumn Header="Результаты" Width="2*" CanUserReorder="False" CanUserSort="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ListBox ItemsSource="{Binding Stageresults, Mode=OneWay}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTextColumn Binding="{Binding MainContractStage, Mode=OneWay}" Header="Этап ген. договора" Width="*" CanUserSort="False" CanUserReorder="False" x:Name="GeneralStageColumn"/>
                            
                            
                        </DataGrid.Columns>
                    </DataGrid>
                    
                </Grid>
            </TabItem>
        </TabControl>
        <Button  Height="30" HorizontalAlignment="Stretch" Name="btnSaveAndExit" VerticalAlignment="Top" Width="270" Command="{Binding Path=SaveImportResultsCommand}" >
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
                <Image Source="/MContracts;component/Resources/save_all.png"   Width="16" Height="16" HorizontalAlignment="Left" />
                <TextBlock Margin="5,0,0,0" Text="Передать результат в редактор договора"  HorizontalAlignment="Right" />
            </StackPanel>
        </Button>
            
    </Grid>
</Window>
